<template>
  <div>
    <div class="login_title">
      智能奶茶后台管理系统
    </div>
    <div class="login_container">
      <div class="login_box">
        <el-form :model="form" label-width="40px">
          <el-form-item label="账号">
            <el-input v-model="form.username"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="form.password"></el-input>
          </el-form-item>
          <el-form-item label-width="80px">
            <el-button type="primary" @click="login">立即登录</el-button>
            <el-button type="success" @click="registry">点击注册</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import qs from "qs";

export default {
  name: "Login",
  data() {
    return {
      form: {
        username: 'admin',
        password: '666',
        checkCode: ''
      }
    }
  },

  methods: {
    login: function () {
      this.check();
      var that = this;
      axios.post("http://localhost:8081/login", qs.stringify(this.form)).then(function (result) {
        that.resultHandler(result);
      })
    },
    check: function () {

    },
    registry: function () {
      alert('注册');
    },

    resultHandler: function (result) {
      var status = result.data.status;
      var msg = result.data.msg;
      var name = result.data.data.name;
      var roleId = result.data.data.roleId;
      if (status === 1) {
        this.$message({
          message: msg,
          center: true,
          type: "success"
        });
        //跳转到首页
        this.$router.push({
          path:'/home',
          query:{
            name:name,
            roleId: roleId
          }
        });
      } else {
        this.$message({
          message: msg,
          center: true,
          type: "error"
        })
      }
    }
  }
}
</script>


<style>
.login_title {
  margin: 70px auto;
  font-family: 黑体;
  font-size: xxx-large;
  text-align: center;
}

.login_container {
  border: 3px solid;
  border-radius: 30px;
  width: 500px;
  height: 260px;
  margin: 60px auto;
  padding-top: 50px;
}

.login_box {

  width: 400px;
  height: 200px;
  margin: auto;
}
</style>
